package com.lemt.mall.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lemt.common.result.Res;
import com.lemt.mall.entity.Category;
import com.lemt.mall.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zik
 * @since 2023-09-10
 */
@Api(tags = "分类操作")
@RestController
@RequestMapping("/mall/category/admin")
public class CategoryController {

    @Resource(name = "CategoryService")
    private ICategoryService categoryService;

    @ApiOperation("保存分类")
    @ApiOperationSupport(includeParameters = {"categoryName"})
    @PostMapping("/saveCategory")
    public Res<Boolean> saveCategory(@RequestBody Category category){
        return Res.ok(categoryService.save(category));
    }

    /**
     * 没写完-----------------------------------------------------------------------------
     * 删除分类后应该删除该分类下的订单、购物车、商品
     * @param id
     * @return
     */
    @ApiOperation("根据id删除分类")
    @DeleteMapping("/removeCategory/{id}")
    public Res<Boolean> removeCategory(@PathVariable Integer id){
        return Res.ok(categoryService.removeById(id));
    }

    @ApiOperation("获取所有分类")
    @GetMapping("getAllCategory")
    public Res<List<Category>> getList(){
        return Res.ok(categoryService.list());
    }

}
